package util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class DateUtil {
	private static SimpleDateFormat sDateFormat=new SimpleDateFormat("dd");
	
	public static List<String> get_dateList(){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.MONTH, -1);
		
		Calendar cal2 = Calendar.getInstance();
		cal2.setTime(new Date());
		cal2.add(Calendar.MONTH, 0);
		
		List<Date> list = getBetweenDates(cal.getTime(),cal2.getTime());
		List<String> resultDate=new ArrayList<>();
		for (Date date : list) {
			resultDate.add(sDateFormat.format(date));
		}
		return resultDate;
	}
	 private static List<Date> getBetweenDates(Date begin, Date end) {
         List<Date> result = new ArrayList<Date>();
         Calendar tempStart = Calendar.getInstance();
         tempStart.setTime(begin);
         Calendar tempEnd = Calendar.getInstance();
         tempStart.add(Calendar.DAY_OF_YEAR, 1);
         tempEnd.setTime(end);
         while (tempStart.before(tempEnd)) {
             result.add(tempStart.getTime());
             tempStart.add(Calendar.DAY_OF_YEAR, 1);
         }
      while(begin.getTime()<=end.getTime()){
          result.add(tempStart.getTime());
          tempStart.add(Calendar.DAY_OF_YEAR, 1);
          begin = tempStart.getTime();
      }
         return result;
 }
}
